package com.sxz.sbs.module.staff.presenter;

import com.sxz.sbs.app.App;
import com.sxz.sbs.module.staff.mode.DepartmentListBean;
import com.sxz.sbs.module.staff.mode.PositionListBean;
import com.sxz.sbs.module.staff.view.AddStaffView;
import com.sxz.sbs.rx.RxPresenter;
import com.sxz.sbs.rx.RxSubscriber;
import com.sxz.sbs.rx.RxUtil;

import java.util.HashMap;
import java.util.List;

/**
 * 添加员工账号P层
 */

public class AddStaffPresenter extends RxPresenter<AddStaffView>{
    /**
     * 获取部门列表
     * @param map
     */
    public void getDepartmentList (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getDepartmentList(map)
                .compose(RxUtil.<List<DepartmentListBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<DepartmentListBean>>(mView){
                    @Override
                    public void onNext(List<DepartmentListBean> data) {
                        mView.onGetDepartmentListSuccess(data);
                    }
                })
        );
    }
    /**
     * 获取职位列表
     * @param map
     */
    public void getPositionList (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().getPositionList(map)
                .compose(RxUtil.<List<PositionListBean>>handleResult())
                .subscribeWith(new RxSubscriber<List<PositionListBean>>(mView){
                    @Override
                    public void onNext(List<PositionListBean> data) {
                        mView.onGetPositionListSuccess(data);
                    }
                })
        );
    }
    /**
     * 添加员工
     * @param map
     */
    public void addStaff (HashMap<String,Object> map) {
        addSubscribe(App.getInstance().getApi().addStaff(map)
                .compose(RxUtil.<String>handleResult())
                .subscribeWith(new RxSubscriber<String>(mView){
                    @Override
                    public void onNext(String data) {
                        mView.onAddStaffSuccess();
                    }
                })
        );
    }
}
